<?php
require_once("taskView.php");
require_once(CORE_DIR.'taskModel.php');

class getAction extends authAction{

	function __construct(){
		$this->view = new taskView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$tModel = new taskModel();		
		
		if (isset($get["userid"])) {
			if (isset($get["projectid"])) {
				$tasks = $tModel->getUserTasksByProject($get["projectid"], $get["userid"]);
			}
			else {
				if (isset($get["date"])) {
					$tasks = $tModel->getUserDailyTasks($get["userid"], $get["date"]);
				}
				else {
					$tasks = $tModel->getUserAllTasks($get["userid"]);
				}
			}
		}
		else{
			if (isset($get["projectid"])) {
				if (isset($get["done"]))
					$tasks = $tModel->getDoneTasksByProject($get["projectid"]);
				else
					$tasks = $tModel->getTasksByProject($get["projectid"]); // Getting all users tasks by project
			}
			else {
				$tasks = $tModel->getAllTasks();
			}
		}
		
		$this->view->setProperty("tasks", $tasks);
		$this->view->showGetTasks();
			
	}
}
?>